package com.jxd.petMgr.servlet;

import com.jxd.petMgr.model.PetOwner;
import com.jxd.petMgr.service.IPetOwnerService;
import com.jxd.petMgr.service.impl.PetOwnerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/getMoneyServlet")
public class GetMoneyServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        IPetOwnerService petOwnerService = new PetOwnerServiceImpl();
//        String msg = request.getParameter("msg");
        HttpSession session = request.getSession();
        //通过session取到的对象id
        PetOwner master = (PetOwner) session.getAttribute("petOwner");
        int petOwnerId = master.getId();
        PetOwner petOwner = petOwnerService.getOwnerByID(petOwnerId);
        double money = petOwner.getMoney();
        String strMoney = ""+money;
//        request.setAttribute("money",money);
//        request.getRequestDispatcher("petOwner.jsp").forward(request,response);

        PrintWriter pw = response.getWriter();
        pw.write(strMoney);
        pw.flush();
        pw.close();
    }
}
